package classes.managers {
	import classes.buttons.BaseButton;
	import classes.controlers.XML_Controler;
	import classes.global.Global_Properties;
	import classes.scenes.A_Scene;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Kihoonee
	 */
	public class IntroAni_Manager extends A_Scene {
		
		// 부모클래스
		//private var main:Main;
		//private var mc:MovieClip;
		
		private var howToUseBtn:BaseButton;
		private var gameStartBtn:BaseButton;
		private var skipBtn:BaseButton;
		private var nextBtn:BaseButton;
		
		
		public function IntroAni_Manager( _main:Main, _mc:MovieClip ) {
			super( _main, _mc );
			
			mc.introAni_mc.name_mc.nick_txt.text = Global_Properties.nick;
			
			addEvent();
		}
		
		private function addEvent():void {
			howToUseBtn = new BaseButton( mc.howToUse_btn );
			gameStartBtn = new BaseButton( mc.gameStart_btn );
			skipBtn = new BaseButton( mc.skip_btn );
			nextBtn = new BaseButton( mc.next_btn );
			
			howToUseBtn.addEventListener( MouseEvent.CLICK, BtnEvent );
			gameStartBtn.addEventListener( MouseEvent.CLICK, BtnEvent );
			skipBtn.addEventListener( MouseEvent.CLICK, BtnEvent );
			nextBtn.addEventListener( MouseEvent.CLICK, BtnEvent );
			
			mc.introAni_mc.addEventListener("player", playerName );
			mc.introAni_mc.addEventListener("npc", npcName );
		}
		
		private function npcName(e:Event):void {
			mc.introAni_mc.name_mc.gotoAndStop(2);
		}
		
		private function playerName(e:Event):void {
			mc.introAni_mc.name_mc.gotoAndStop(1);
			mc.introAni_mc.name_mc.nick_txt.text = Global_Properties.nick;
		}
		
		public function init():void {
			mc.howToUse_mc.visible = false;
			howToUseBtn.visible = false;
			gameStartBtn.visible = false;
		}
		
		private function introAni_END():void {
			howToUseBtn.visible = true;
			gameStartBtn.visible = true;
			
			skipBtn.visible = false;
			nextBtn.visible = false;
		}
		
		private function gameStart():void {
			trace("게임시작")
			main.viewChange( "game" );
			main.gameInit();
		}
		
		
		private function BtnEvent(e:MouseEvent):void {
			switch ( e.target.name ) {
				case "howToUse_btn":
					mc.howToUse_mc.visible = true;
					howToUseBtn.visible = false;
				break;
				case "gameStart_btn":
					gameStart();
				break;
				case "skip_btn":
					mc.introAni_mc.gotoAndStop( mc.introAni_mc.totalFrames );
					introAni_END();
				break;
				case "next_btn":
					mc.introAni_mc.nextFrame();
					if ( mc.introAni_mc.currentFrame == mc.introAni_mc.totalFrames ) {
						introAni_END();
					}
				break;
				default:
			}
		}
		
	}

}